import { ref } from 'vue'
import { useAuth } from './useAuth'

export const useStore = () => {
  const { user, isAuthenticated, login, register, logout, checkAuth } = useAuth()

  // 全局主题设置
  const theme = ref<'light' | 'dark'>('light')
  const toggleTheme = () => {
    theme.value = theme.value === 'light' ? 'dark' : 'light'
    document.documentElement.setAttribute('data-theme', theme.value)
  }

  // 全局通知
  const notifications = ref<Array<{
    id: number
    type: 'success' | 'error' | 'info' | 'warning'
    message: string
    duration?: number
  }>>([])

  const addNotification = (type: 'success' | 'error' | 'info' | 'warning', message: string, duration = 3000) => {
    const id = Date.now()
    notifications.value.push({ id, type, message, duration })
    if (duration > 0) {
      setTimeout(() => {
        removeNotification(id)
      }, duration)
    }
  }

  const removeNotification = (id: number) => {
    notifications.value = notifications.value.filter(n => n.id !== id)
  }

  // 全局加载状态
  const isLoading = ref(false)
  const setLoading = (loading: boolean) => {
    isLoading.value = loading
  }

  return {
    // 用户认证
    user,
    isAuthenticated,
    login,
    register,
    logout,
    checkAuth,

    // 主题
    theme,
    toggleTheme,

    // 通知
    notifications,
    addNotification,
    removeNotification,

    // 加载状态
    isLoading,
    setLoading
  }
} 